﻿using CMS.Controls.DisplayTabPages.SettingTabPages;
using System.Windows.Forms;

namespace CMS.Controls.DisplayTabPages
{
    public partial class SettingTabPage : MainFormTabPageTemplate
    {
        public SettingTabPage()
        {
            InitializeComponent();
            _DisplayTab<LazyEditorTabPage<AssistantEditorTabAdapter>>("助理信息");
            _DisplayTab<LazyEditorTabPage<TermEditorAdapter>>("学期信息");
            _DisplayTab<LazyEditorTabPage<RoomEditorAdaptor>>("课室信息");
            _DisplayTab<LazyEditorTabPage<CourseAdjustEditorTabAdapter>>("调换课信息");
            _DisplayTab<LazyEditorTabPage<BuildingEditorAdapter>>("值班地点");
            _DisplayTab<LazyEditorTabPage<UserEditorTabAdapter>>("用户管理");

        }

        private void _DisplayTab<T>(string text, string name = null, bool active = false) where T : TabPage, new()
        {
            if (name == null)
            {
                name = typeof(T).ToString();
            }

            if (TC_Second.TabPages.ContainsKey(name))
            {
                TabPage page = TC_Second.TabPages[name];
                if (active)
                {
                    TC_Second.SelectedTab = page;
                }
            }
            else
            {
                T page = new T() { Name = name, Text = text };
                TC_Second.TabPages.Add(page);
                if (active)
                {
                    TC_Second.SelectedTab = page;
                }
            }
        }

    }
}
